package com.neuedu.his.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.neuedu.his.po.Fmeditem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FmeditemMapper extends BaseMapper<Fmeditem> {
    /**
     * 根据条件查询非药品项目
     * @param recordTypes 记录类型列表
     * @param keyword 关键词（项目名称或助记码）
     * @return 非药品项目列表
     */
    @Select("<script>" +
            "SELECT * FROM Fmeditem " +
            "WHERE DelMark = 0 " +
            "<if test='recordTypes != null and recordTypes.size() > 0'>" +
            "AND RecordType IN " +
            "<foreach item='type' collection='recordTypes' open='(' separator=',' close=')'>" +
            "#{type}" +
            "</foreach> " +
            "</if>" +
            "<if test='keyword != null and keyword != \"\"'>" +
            "AND (ItemName LIKE CONCAT('%', #{keyword}, '%') " +
            "OR ItemCode LIKE CONCAT('%', #{keyword}, '%') " +
            "OR MnemonicCode LIKE CONCAT('%', #{keyword}, '%')) " +
            "</if>" +
            "ORDER BY ItemName" +
            "</script>")
    List<Fmeditem> getFmeditemsByCondition(@Param("recordTypes") List<Integer> recordTypes,
                                           @Param("keyword") String keyword);
}